package labelsystem.Service.Implements;/**
 * @projectName careOlder
 * @Description TODO
 * @author MCG
 * @time 2023/4/1 16:16
 */

import labelsystem.Mapper.monitorMapper;
import labelsystem.Mapper.ouserMapper;
import labelsystem.Pojo.Monitor;
import labelsystem.Pojo.OlderUser;
import labelsystem.Service.scheduleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 *description: TODO
 *@author MCG
 *@date 2023/4/1 16:16
 *@Version 1.0
 */
@Service
public class scheduleServiceImplement implements scheduleService {
    @Resource
    monitorMapper monitorMapper;

    @Resource
    ouserMapper ouserMapper;

    @Override
    public List<Long> needMonitor() {
        List<Long> res=new ArrayList<>();
        List<Monitor> monitors=monitorMapper.selectList(null);
        for(Monitor temp:monitors){
            LocalDateTime localDateTime=LocalDateTime.now();
            LocalDateTime createTime=temp.getCreateTime();
            Duration duration=Duration.between(createTime,localDateTime);
            Integer index=Integer.parseInt(String.valueOf(duration.toDays()));
            if(index>(temp.getIsUsed().length())){
                monitorMapper.deleteById(temp.getId());
                continue;
            }
            if(temp.getIsUsed().charAt(index)=='0'){
                OlderUser olderUser=ouserMapper.selectById(temp.getId());
                res.add(olderUser.getPhone());
            }
        }
        return res;
    }
}
